package com.drought.rained.presenter;

import com.drought.rained.BuildConfig;
import com.drought.rained.business.CustomConsumerLJ;
import com.drought.rained.business.ParamsFactoryLJ;
import com.drought.rained.cache.UserInfoLJ;
import com.drought.rained.mvpview.BillMvpViewLJ;
import com.drought.rained.response.OrderDetailResponseLJ;
import com.drought.rained.response.OrderItemResponseLJ;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.functions.Consumer;

public class BillPresenterLJ extends BasePresenterLJ {
    private BillMvpViewLJ mvpView;

    public BillPresenterLJ(BillMvpViewLJ mvpView) {
        this.mvpView = mvpView;
    }

    public void getOrderPageList(int mCurrentPage) {
        Map<String, Object> formMap = new HashMap<>();
        formMap.put("limit", "10"); // 每页10条
        formMap.put("page", String.valueOf(mCurrentPage));
        toSubScribe(req.getOrderPageList(BuildConfig.channel, UserInfoLJ.getToken(), ParamsFactoryLJ.getCommonParams(formMap)), new CustomConsumerLJ<OrderItemResponseLJ>() {
            @Override
            public void call(OrderItemResponseLJ updateResponse) {
                mvpView.onGetDataNext(updateResponse);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }

    public void getOrderDetail(String orderId, final int position) {
        Map<String, Object> fromMap = new HashMap<>();
        fromMap.put("orderId", orderId);
        toSubScribe(req.getOrderDetail(BuildConfig.channel, UserInfoLJ.getToken(), ParamsFactoryLJ.getCommonParams(fromMap)), new CustomConsumerLJ<OrderDetailResponseLJ>() {
            @Override
            public void call(OrderDetailResponseLJ updateResponse) {
                mvpView.onGetDataNext(updateResponse, position);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }

}
